import request from '@/utils/request'
import type {
  addRoleParams,
  roleQueryParams,
} from '@/api/back-management/role/interface'
import type { Response, PageDataList } from '@/utils/type'

export interface RoleDataResp {
  createDate?: string
  orderIndex?: number
  pkid: string
  remark?: string
  roleLevel?: number
  roleName: string
  updateDate?: string
}

/**
 * 获取角色列表
 *
 * @param {roleQueryParams} params 查询参数
 */
export const queryRoleList = (
  params: roleQueryParams
): Promise<Response<PageDataList<RoleDataResp>>> => {
  return request('/system/role/query', {
    method: 'GET',
    params,
  })
}

/**
 * 新增角色
 *
 * @param {addRoleParams} params 新增参数
 */
export const addRole = (params: addRoleParams) => {
  return request('/system/role/add', {
    method: 'POST',
    data: params,
  }) as Promise<Response<any>>
}

/**
 * 删除角色
 *
 * @param {string} pkid 主键id
 */
export const deleteRole = (pkid: string) => {
  return request('/system/role/delete', {
    method: 'DELETE',
    params: {
      pkid,
    },
  }) as Promise<Response<any>>
}

/**
 * 编辑角色
 *
 * @param {pkid} pkid 角色pkid
 *
 * @param {addRoleParams} params 新增参数
 */
export const editRole = (pkid: string, params: addRoleParams) => {
  return request(`/system/role/update/${pkid}`, {
    method: 'PUT',
    data: params,
  }) as Promise<Response<any>>
}

/**
 * 编辑角色
 *
 *
 * @param {addRoleParams} params 新增参数
 * @param roleId
 * @param resourceType
 */
export const bindRolePermission = (
  data: any,
  // roleId: any,
  // resourceType = 4
) => {
  // console.log(roleId)
  return request(`/system/pri/role/addBatch`, {
    method: 'POST',
    data: data,
    // params: {
    //   resourceType: resourceType,
    //   roleId: roleId,
    // },
  }) as Promise<Response<any>>
}

/**
 * 编辑角色
 *
 * @param {roleId} roleId 角色id
 *
 * @param {type} type 资源类型
 */
export const queryRolePermission = (roleId: string) => {
  return request(
    `/resource/datacatalog/menu/pri/query?roleId=${roleId}`,
    {
      method: 'GET',
    }
  ) as Promise<Response<any>>
}
